<template>
    <div id="myChart" :style="{ width: '100%', height: '120px' }"></div>
</template>

<script>
import * as echarts from 'echarts'
export default {
    props: {
        lineData: {
            type: Array,
            default: [],
        },
    },
    data() {
        return {}
    },
    watch: {
        lineData(val) {
            this.lineData = val
            this.drawLine()
        },
    },
    mounted() {
        this.drawLine()
    },
    methods: {
        drawLine() {
            let myChart = new echarts.init(document.getElementById('myChart'))
            myChart.setOption({
                title: {
                    text: '',
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                        type: 'shadow',
                        label: {
                            backgroundColor: '#6a7985',
                        },
                    },
                },
                legend: {
                    show: false,
                    data: ['消息数'],
                    left: 'center',
                    top: 'bottom',
                    padding: [0, 50],
                    textStyle: {
                        color: '#fff',
                        lineHeight: 18,
                    },
                },
                grid: {
                    top: '25%',
                    left: '3%',
                    right: '3%',
                    bottom: 0,
                    containLabel: true,
                },
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: ['7:00-8:00','8:00-11:00', '11:00-12:30','12:30-1:00', '1:00-2:30', '2:30-5:00','5:00-6:00'],
                    axisTick: {
                        show: false,
                    },
                },
                yAxis: {
                    type: 'value',
                    splitLine: {
                        show: false,
                    },
                    axisLabel: {
                        show: false,
                    },
                },
                series: [
                    {
                        name: '消息数',
                        type: 'line',
                        itemStyle: {
                            color: '#7DAAC8',
                            normal: {
                                color: function (params) {
                                    return new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                        {
                                            offset: 0,
                                            color: '#7DAAC8',
                                        },
                                        {
                                            offset: 1,
                                            color: '#7DAAC830',
                                        },
                                    ])
                                },
                            },
                        },
                        lineStyle: {
                            width: 2,
                        },
                        areaStyle: {
                            normal: {
                                //颜色渐变函数 前四个参数分别表示四个位置依次为左、下、右、上
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                                    {
                                        offset: 0,
                                        color: 'rgba(80,141,255,0.8)',
                                    },
                                    {
                                        offset: 0.34,
                                        color: 'rgba(56,155,255,0.4)',
                                    },
                                    {
                                        offset: 1,
                                        color: 'rgba(38,197,254,0.1)',
                                    },
                                ]),
                            },
                        },
                        symbolSize: 0,
                        smooth: true,
                        data: this.lineData,
                    },
                ],
            })
        },
    },
}
</script>